import React from "react";
import { View, Text, TouchableOpacity, StyleSheet } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";

const TopNavBar = ({
  title,
  leftText,
  onLeftPress,
  rightText,
  onRightPress,
}: any) => {
  const insets = useSafeAreaInsets();

  return (
    <View style={[styles.container, { paddingTop: insets.top }]}>
      {leftText && (
        <TouchableOpacity onPress={onLeftPress} style={styles.leftButton}>
          <Text style={styles.buttonText}>{leftText}</Text>
        </TouchableOpacity>
      )}
      <Text style={styles.title}>{title}</Text>
      {rightText && (
        <TouchableOpacity onPress={onRightPress} style={styles.rightButton}>
          <Text style={styles.buttonText}>{rightText}</Text>
        </TouchableOpacity>
      )}
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flexDirection: "row",
    justifyContent: "space-between",
    alignItems: "center",
    backgroundColor: "#fff",
    height: 50,
    borderBottomWidth: 1,
    borderBottomColor: "#ccc",
  },
  leftButton: {
    paddingLeft: 15,
  },
  rightButton: {
    paddingRight: 15,
  },
  title: {
    fontSize: 18,
    fontWeight: "bold",
  },
  buttonText: {
    fontSize: 16,
  },
});

export default TopNavBar;
